﻿var myDocument = app.activeDocument;
var wenBen_MuBiao = new Array("།", " ། ","༑"," ༑ ", "ག། ","༔"," ༔","། །། །")//把要改的字符加在数组里
var wenBen_JieGuo = new Array("། ", " །","༑ "," ༑", "ག །","༔ ","༔","།། །།")//改动的结果

var grep_MuBiao = new Array("། *། *། *། *")//把要改的正则表达式加在数组里
var grep_JieGuo = new Array("།། །།")//改动的结果

grep_TiHuan("[ 　]{1,}", " ");
for (n=0; n<wenBen_MuBiao.length; n++){
    MuBiao = wenBen_MuBiao[n];
    JieGuo = wenBen_JieGuo[n];
    wenBen_TiHuan(MuBiao, JieGuo);        
}
for (n=0; n<grep_MuBiao.length; n++){
    MuBiao = grep_MuBiao[n];
    JieGuo = grep_JieGuo[n];
    grep_TiHuan(MuBiao, JieGuo);        
}
grep_TiHuan("[ 　]{1,}", "  ");
alert("完工！")

function wenBen_TiHuan(MuBiao, JieGuo){
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    app.findTextPreferences.findWhat = MuBiao;
    app.changeTextPreferences.changeTo = JieGuo;
    myDocument.changeText();
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
}

function grep_TiHuan(MuBiao, JieGuo){
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findChangeGrepOptions.includeFootnotes = false;
    app.findChangeGrepOptions.includeHiddenLayers = false;
    app.findChangeGrepOptions.includeLockedLayersForFind = false;
    app.findChangeGrepOptions.includeLockedStoriesForFind = false;
    app.findChangeGrepOptions.includeMasterPages = false;
    app.findGrepPreferences.findWhat = MuBiao;
    app.changeGrepPreferences.changeTo = JieGuo;
    myDocument.changeGrep();
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
}